package gdatastructure;

public class Link{
	VNode first;//第一个节点
	VNode current;//当前节点
		
	Link(){
		first = null;
		current = null;
	}
//	void update(int cir)
//        {
//            current.setcir(cir);
//        }
	//增加一个邻接点，放在链表开始处
	void add(int to, int linkvalue){
		VNode tempnode = new VNode(to, linkvalue);
		if(first == null)
			first = tempnode;
		else
		{
			tempnode.next(first);
			first = tempnode;
		}
	}
	
	boolean hasNext(){  //是有否用下一个
		return current == null ? first != null : current.next() != null; //三目运算
	}
	
	VNode next(){ //下一个
		if(current == null)
			current = first;
		else
			current = current.next();
		return current;
	}
        
	void reset(){
		current = null;
	}
	//删除一个索引号为index的结点
	void remove(int index){
		VNode pre = null;
		VNode cur = first;
		
		while(cur != null)
		{
			if(cur.index() == index)
			{
				if(pre == null)
				{
					first = cur.next();
				}
				else
				{
					pre.next(cur.next());
				}
				return;
			}
			pre = cur;
			cur = cur.next();
		}
		
	}
}
